{% load static %}
{% load i18n %}
<div class="layui-header layui-fluid">
    <div class="" style="display:flex;flex-direction:row;justify-content:space-between;">
        <!-- LOGO -->
        <div class="">
            <a class="logo" href="{% url 'pro_list' %}">
                <img src="{% static 'logo.svg' %}" style="height: 32px;width: auto;">
            </a>
        </div>
        <!-- 搜索框 -->
        <div style="margin:12px;" class="layui-hide-xs">
            {% if search_type == '1' %}
            <form method="get" action="{% url 'doc_search' %}" target="_blank">
                <div class="layui-input-inline">
                    <input class="layui-input mrdoc-search-input" placeholder="{% trans '搜索文档' %}" name="q"/>
                    <button type="submit" style="position: absolute;top:12px;right: 8px;border: none;background-color: white;">
                        <i class="layui-icon layui-icon-search" ></i>
                    </button>
                </div>
            </form>
            {% else %}
            <form method="get" action="{% url 'search' %}" target="_blank">
                <input name="type" value="doc" hidden />
                <div class="layui-input-inline">
                    <input class="layui-input mrdoc-search-input" placeholder="{% trans '搜索文档' %}" name="kw"/>
                    <button type="submit" style="position: absolute;top:12px;right: 8px;border: none;background-color: white;">
                        <i class="layui-icon layui-icon-search" ></i>
                    </button>
                </div>
            </form>
            {% endif %}
        </div>
        <div class="layui-hide-lg layui-hide-md layui-hide-sm" style="margin:20px;">
            <a href="{% url 'search' %}">
                <i class="layui-icon layui-icon-search" style="font-size: 24px;"></i>
            </a>
        </div>
        
        <!-- 新建文档按钮 -->
        {% if request.user.is_authenticated %}
        <div class="layui-hide-xs">
            <ul class="layui-nav">
                <li class="layui-nav-item">
                    <a>
                        <i class="layui-icon layui-icon-add-circle" style="color:black;"></i> <span>{% trans "新建" %}</span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd>
                            <a href="{% url 'create_doc' %}">
                                <img src="{% static 'icon_img/create-doc-icon.svg' %}" height="14px" width="14px"></img>
                                <span class="layui-hide-xs">{% trans "新建文档" %}</span>
                            </a>
                        </dd>
                        <dd>
                            <a href="{% url 'create_doc' %}?eid=4">
                                <img src="{% static 'icon_img/create-table-icon.svg' %}" height="14px" width="14px"></img>
                                <span class="layui-hide-xs">{% trans "新建表格" %}</span>
                            </a>
                        </dd>
                        <dd>
                            <a href="javascript:void(0);" onclick="createPro();">
                                <img src="{% static 'icon_img/create-pro-icon.svg' %}" height="14px" width="14px"></img>
                                <span class="layui-hide-xs">{% trans "新建文集" %}</span>
                            </a>
                        </dd>
                    </dl>
                </li>
            </ul>
        </div>
        {% endif %}
        <!-- 用户菜单 -->
        <div class="">
            <ul class="layui-nav layui-layout-right">
                {% if request.user.is_authenticated %}
            <li class="layui-nav-item">
                <a href="javascript:void(0);">
                    <i class="layui-icon layui-icon-friends"></i> 
                    <span class="layui-hide-xs">{% if request.user.first_name != '' %} {{request.user.first_name}} {% else %} {{request.user.username}}{% endif %}</span>
                </a>
                <dl class="layui-nav-child">
                    {% if request.user.is_superuser %}
                    <dd>
                        <a href="{% url 'admin_center' %}" title="进入站点后台管理">
                            <i class="layui-icon layui-icon-console layui-hide-md"></i>
                            <span class="layui-hide-xs">{% trans "进入后台" %}</span>
                        </a>
                    </dd>
                    {% endif %}
                    <dd class="layui-hide-md layui-hide-sm layui-hide-lg">
                        <a href="{% url 'create_doc' %}" title="新建文档">
                            <i class="layui-icon layui-icon-add-1 layui-hide-md"></i>
                            <span class="layui-hide-xs">{% trans "新建文档" %}</span>
                        </a>
                    </dd>
                    <dd>
                        <a href="{% url 'user_center' %}" title="个人中心">
                            <i class="layui-icon layui-icon-app layui-hide-md"></i>
                            <span class="layui-hide-xs">{% trans "个人中心" %}</span>
                        </a>
                    </dd>
                    <dd>
                        <a href="javascript:void(0);" onclick="changePwd('{{ request.user.id }}','{{ request.user.username }}' )" title="修改登录密码">
                            <i class="layui-icon layui-icon-password layui-hide-md"></i>
                            <span class="layui-hide-xs">{% trans "修改密码" %}</span>
                        </a>
                    </dd>
                    <dd>
                        <a href="javascript:void(0)" title="退出登录" onclick="Logout()">
                            <i class="layui-icon layui-icon-logout layui-hide-md"></i>
                            <span class="layui-hide-xs">{% trans "退出登录" %}</span>
                        </a>
                    </dd>
                </dl>
            </li>
                {% else %}
                <li class="layui-nav-item">
                <a href="javascript:void(0);">
                <i class="layui-icon layui-icon-username"></i> {% trans "游客" %}
                </a>
                <dl class="layui-nav-child">
                    {% if close_register == 'on' %}
                    <dd>
                        <a href="{% url 'login' %}">
                            <i class="iconfont mrdoc-icon-denglu"></i>
                            {% trans "登录" %}
                        </a>
                    </dd>
                    {% else %}
                    <dd>
                        <a href="{% url 'register' %}">
                            <i class="iconfont mrdoc-icon-zhuce"></i>
                            {% trans "注册" %}
                        </a>
                    </dd>
                    <dd>
                        <a href="{% url 'login' %}">
                            <i class="iconfont mrdoc-icon-denglu"></i>
                            {% trans "登录" %}
                        </a>
                    </dd>
                    {% endif %}
                </dl>
            </li>
                {% endif %}
            </ul>
        </div>
    </div>
</div>
<script>
    function Logout(){
        $.ajax({
            url:"{% url 'logout' %}",
            method:'post',
            success:function(r){
                if(r.status){
                    window.location.href = r.data
                }else{
                    layer.msg("注销失败")
                }
            },
            error:function(){
                layer.msg("注销失败")
            }
        })
    }
</script>